package com.lxq.www.enumeration.enumconverter;


import com.lxq.www.enumeration.SexEnum;

import javax.persistence.AttributeConverter;

public class SexConverter implements AttributeConverter<SexEnum, String> {
    @Override
    public String convertToDatabaseColumn(SexEnum sexEnum) {
        if (sexEnum==null){
            sexEnum=SexEnum.SECRET;
        }
        return sexEnum.getSex();
    }

    @Override
    public SexEnum convertToEntityAttribute(String sex) {
        switch (sex){
            case "女":
                return SexEnum.FEMALE;
            case "男":
                return SexEnum.MALE;
            default:
                return SexEnum.SECRET;
        }
    }
}
